package hu;

public class th_sy{
    private static int i = 0;
    private static Object object = new Object();
    public static void main(String[] args) {

        new Thread(new my_threadA(),"A").start();
        new Thread(new my_threadB(),"B").start();
    }

    static class my_threadA implements Runnable{

        @Override
        public void run() {
            while(i < 100){
                synchronized (object){
                    if(i % 2 == 0){
                        System.out.println(Thread.currentThread().getName() + "-->" + ++i);
                    }
                }
            }
        }
    }
    static class my_threadB implements Runnable{
        @Override
        public void run() {
            while(i < 100){
                synchronized (object){
                    if(i % 2 == 1){
                        System.out.println(Thread.currentThread().getName() + "-->" + ++i);
                    }
                }
            }
        }
    }
}